// page/component/details/details.js
const app = getApp()
Page({
    data:{
        windowHeight: 654,
        maxtime: "",
        isHiddenLoading: true,
        isHiddenToast: true,
        dataList: {},
        countDownDay: 0,
        countDownHour: 0,
        countDownMinute: 0,
        countDownSecond: 0,
        goods: {},
      goods1: {
        id: 1,
        image: 'https://z3.ax1x.com/2021/06/14/2786G6.jpg',
        title: '蒙都牛肉干5kg',
        price: 99,
        stock: 233,
        detail: '这里是详情。',
        parameter: '125g/个',
        service: '不支持退货',
        time_remaining:23,//剩余时间，记录小时
        day:0
      },
      comment_list:[],
      comment_list1:[
        {
            id:0,
            username:'123',
            comment:"商品不错，下次还来回购",
            imageUrl:'/images/banggou.jpg',
            pictures:[
              'https://z3.ax1x.com/2021/06/14/2786G6.jpg',
              'https://z3.ax1x.com/2021/07/05/RhJtQP.jpg',
              'https://z3.ax1x.com/2021/07/05/RhJJzt.jpg'
          ],
            star: 3.5,//评分
            date:"2021-6-23"
            
        },
        {
          id:1,
          username:'123',
          comment:"商品不错，下次还来回购。哈哈哈哈哈哈哈哈很好很好拍啊",
          imageUrl:'/images/banggou.jpg',
          pictures:[
            'https://z3.ax1x.com/2021/06/14/2786G6.jpg',
            'https://z3.ax1x.com/2021/07/05/RhJtQP.jpg',
            'https://z3.ax1x.com/2021/07/05/RhJJzt.jpg'
        ],
          star: 3.5,//评分
          date:"2021-6-23"
          
      },
      {
        id:2,
        username:'123',
        comment:"商品不错，下次还来回购，不错，刚好需要。",
        imageUrl:'/images/banggou.jpg',
        pictures:[
          'https://z3.ax1x.com/2021/06/14/2786G6.jpg',
          'https://z3.ax1x.com/2021/07/05/RhJtQP.jpg',
          'https://z3.ax1x.com/2021/07/05/RhJJzt.jpg'
      ],
        star: 3.5,//评分
        date:"2021-6-23"

      },
      {
        id:3,
        username:'123',
        comment:"商品不错，下次还来回购，商品不错，下次还来回购，商品不错，下次还来回购",
        imageUrl:'/images/banggou.jpg',
        pictures:[
          'https://z3.ax1x.com/2021/06/14/2786G6.jpg',
          'https://z3.ax1x.com/2021/07/05/RhJtQP.jpg',
          'https://z3.ax1x.com/2021/07/05/RhJJzt.jpg'
      ],
        star: 3.5,//评分
        date:"2021-6-23"
      },
      {
        id:4,
        username:'123',
        comment:"商品不错，下次还来回购，商品不错，下次还来回购，商品不错，下次还来回购，商品不错，下次还来回购，商品不错，下次还来回购",
        imageUrl:'/images/banggou.jpg',
        pictures:[
          'https://z3.ax1x.com/2021/06/14/2786G6.jpg',
          'https://z3.ax1x.com/2021/07/05/RhJtQP.jpg',
          'https://z3.ax1x.com/2021/07/05/RhJJzt.jpg'
      ],
        star: 3.5,//评分
        date:"2021-6-23"
    },
    {
      id:5,
      username:'123',
      comment:"商品不错，下次还来回购",
      imageUrl:'/images/banggou.jpg',
    //   pictures:[
    //     'https://z3.ax1x.com/2021/06/14/2786G6.jpg',
    //     'https://z3.ax1x.com/2021/07/05/RhJtQP.jpg',
    //     'https://z3.ax1x.com/2021/07/05/RhJJzt.jpg'
    // ],
      star: 3.5,//评分
      date:"2021-6-23"
  }],
      num: 1,
      totalNum: 0,
      hasCarts: false,
      curIndex: 0,
      show: false,
      scaleCart: false
    },
  
    addCount() {
      let num = this.data.num;
      num++;
      this.setData({
        num : num
      })
    },
  
    addToCart() {
      const self = this;
      const num = this.data.num;
      let total = this.data.totalNum;
  
      self.setData({
        show: true
      })
      setTimeout( function() {
        self.setData({
          show: false,
          scaleCart : true
        })
        setTimeout( function() {
          self.setData({
            scaleCart: false,
            hasCarts : true,
            totalNum: num + total
          })
        }, 200)
      }, 300)
  
    },
  
    bindTap(e) {
      const index = parseInt(e.currentTarget.dataset.index);
      this.setData({
        curIndex: index
      })
    },

    //处理倒计时
    //事件处理函数
 bindViewTap: function() {
    wx.navigateTo( {
     url: '../logs/logs'
    })
   },
   onLoad: function(options) {
    this.setData( {
     windowHeight: wx.getStorageSync( 'windowHeight' )
    });
    this.getDetail(options.id);
    this.getComments(options.id);
   },

   getDetail: function(id){
    var that = this;
    that.data.token = app.getToken()
    console.log(that.data.token)
    //网络请求获取账单数据
  //   wx.request({
  //     url: 'http://localhost:8080/community/helphelp/detail?id='+id,
  //     method:'GET',
  //     header:{
  //       'content-type': 'application/json',
  //       'Authorization':  that.data.token
  //     },
  //     success:function(res){
  //       // console.log("userInfo" + JSON.stringify(res))
  //       that.setData({
  //         goods: res.data.data
  //       });

  //     }
   

  //  })
  app.sendGetRequest("/community/helphelp/detail?id="+id,(res) => {
    that.setData({
      goods: res.data
    });
   })
  },
  getComments: function(id){
    var that = this;
    that.data.token = app.getToken()
    console.log(that.data.token)
    //网络请求获取账单数据
  //   wx.request({
  //     url: 'http://localhost:8080/community/helphelp/comments?id='+id,
  //     method:'GET',
  //     header:{
  //       'content-type': 'application/json',
  //       'Authorization':  that.data.token
  //     },
  //     success:function(res){
  //       // console.log("userInfo" + JSON.stringify(res))
  //       console.log(res)
  //       // that.setData({
  //       //   comment_list: res.data.data
  //       // });
  //       var c = res.data.data;
  //       for(var i=0;i<c.length;i++){
  //         var pictures = c[i].contentPicture;
  //         var p = JSON.parse(pictures);
  //         c[i].contentPicture = p;
  //         that.setData({
  //           comment_list: c
  //         });
  //       }


  //     }
   

  //  })
  app.sendGetRequest("/community/helphelp/comments?id="+id, (res)=>{
    var c = res.data;
    for(var i=0;i<c.length;i++){
      var pictures = c[i].contentPicture;
      var p = JSON.parse(pictures);
      c[i].contentPicture = p;
      that.setData({
        comment_list: c
      });
    }
   })
  },
   
   //cell事件处理函数
   bindCellViewTap: function (e) {
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
     url: '../babyDetail/babyDetail?id=' + id
    });
   }
    
  })